package org.csu.mypetstore.thread;

import jakarta.servlet.http.HttpSession;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

@EqualsAndHashCode(callSuper = true)
@Component
@Data
@Log4j2
public class RemoveCodeThread extends Thread{
    HttpSession session;
    @Override
    public void run(){
        try {
            Thread.sleep(1000*60);
            String phoneCode = (String)session.getAttribute("PhoneCode");
            if(phoneCode != null){
                session.removeAttribute("PhoneCode");
            }else{
                session.removeAttribute("EmailCode");
            }

            log.info("验证码删除成功");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    public RemoveCodeThread(HttpSession session){
        this.session = session;
    }

}
